//Parser object that contains all parser for all skins
//Parser = function Parser() {}; //No need to initialize

/**
 * @function namespace/signatrue - Component type : Control type : Parser.formskin : Parser.impl
 * conf - configuration properties for layout
 * prop - properties
 * parentconf - parent element conf
 * parentprop - parent element prop
 */
/*Parser["control:popupinput:default:Json2htmlParser:html"] = function(conf, prop, parentconf, parentprop) {
	Parser.log(JSON.stringify(parentconf));
	Parser.log(JSON.stringify(parentprop));
	return '<span class="label"'+
				(prop["i18ntip-"+Parser.lang] ? (' original-title="'+prop["i18ntip-"+Parser.lang]+'"') : '')
				+ '>'+prop["i18nname-"+Parser.lang]+'</span>'+
			'<span class="item input-s">'+
				'<input class="input-xz input_s" id="'+conf.id+'" name="'+conf.id+
				'" type="text" value=""'+
				(prop.disabled=='1' ? ' readonly="readonly"' : '') +
				(prop["processbinding-displayvalue"] ? (' binding="'+prop["processbinding-displayvalue"]+'"') : '')+
				' desc="'+prop["i18nname-"+Parser.lang]+'"'+
				' databinding="'+prop["databinding-displayvalue"]+'" maxlength="'+ prop.maxlength + '"' +
				' ng-model="b.'+prop["databinding-displayvalue"]+'"' +
				//' ng-bind="b.'+prop["databinding-displayvalue"]+'"' +
				' onchange="fmdf.onPopupinputChange(event)"' +
				'/>'+
				'<span class="tip inp-tip" onclick="fmdf.onPopupinputBtnClick(event)"><i class="icon-find"></i></span>'+
				//hidden for realvalue
				'<input name="'+conf.id+
				'" type="hidden" value=""'+
				(prop["processbinding-realvalue"] ? (' binding="'+prop["processbinding-realvalue"]+'"') : '')+
				' desc="'+prop["i18nname-"+Parser.lang]+'"'+
				' databinding="'+prop["databinding-realvalue"]+'"' + 
				' ng-model="b.'+prop["databinding-realvalue"]+'"' +
				//' ng-bind="b.'+prop["databinding-realvalue"]+'"' +
				'"/>'+
			'</span>';
};*/

/**
 * @function namespace/signatrue - Component type : Control type : Parser.formskin : Parser.impl
 * conf - configuration properties for layout
 * prop - properties
 * parentconf - parent element conf
 * parentprop - parent element prop
 */
/*Parser["control:popupinput:bootstrap-blue:Json2htmlParser:html"] = function(conf, prop, parentconf, parentprop) {
	Parser.log(JSON.stringify(parentconf));
	Parser.log(JSON.stringify(parentprop));
	var fmdcols = parseInt(parentconf.fmdcols);
	var cols = [1,fmdcols-1];
	if(fmdcols>3) {
		cols = [2,fmdcols-2];
	}
	return '<div class="col-md-'+cols[0]+'">'+
		    '<p'+
		    (prop["i18ntip-"+Parser.lang] ? (' original-title="'+prop["i18ntip-"+Parser.lang]+'"') : '') +
		    '>'+prop["i18nname-"+Parser.lang]+
		    (required ? '<span class="xh">*</span>' : '') +
		    '</p>'+
		    '</div>'+
		    '<div class="col-md-'+cols[1]+'">'+
			    '<div class="input-group" style="position:relative;">'+
		            '<input type="text" class="form-control" id="'+conf.id+'" name="'+conf.id+
					'" type="text" value=""'+
					(prop.disabled=='1' ? ' readonly="readonly"' : '') +
					(prop["processbinding-displayvalue"] ? (' binding="'+prop["processbinding-displayvalue"]+'"') : '')+
					' desc="'+prop["i18nname-"+Parser.lang]+'"'+
					' databinding="'+prop["databinding-displayvalue"]+'" maxlength="'+ prop.maxlength + '"' +
					' ng-model="b.'+prop["databinding-displayvalue"]+'"' +
					' onchange="fmdf.onPopupinputChange(event)"' +
		            '/>'+
		            '<span class="cancel" onclick="fmdf.onPopupinputBtnClear(event)"><img src="<%=resPath%>/images/cancel.png" width="12" height="12"/></span>'+
		            //hidden for realvalue
					'<input name="'+conf.id+
					'" type="hidden" value=""'+
					(prop["processbinding-realvalue"] ? (' binding="'+prop["processbinding-realvalue"]+'"') : '')+
					' desc="'+prop["i18nname-"+Parser.lang]+'"'+
					' databinding="'+prop["databinding-realvalue"]+'"' + 
					' ng-model="b.'+prop["databinding-realvalue"]+'"' +
					'"/>'+
		            '<span class="input-group-btn">'+
		               '<button type="button" class="btn btn-default btn-xs">'+
		     			'<span class="glyphicon glyphicon-search" style="line-height:2.5 "></span>'+
		               '</button>'+
		            '</span>'+
	            '</div>'+
		    '</div>';
};*/

Parser["control:popupinput:bootstrap-blue:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		Parser.log(JSON.stringify(conf));
		Parser.log(JSON.stringify(prop));
		//Parser.parseDataProvider(conf.id);
		var required = Parser.parseValidator(conf.id);
		Parser.parseI18ntip(conf.id);
		var data = {};
		var transform = {"tag":"i"};
		var fmdcols = parseInt(conf.fmdcols);
		var cols = [1,fmdcols-1];
		if(fmdcols>3) {
			cols = [2,fmdcols-2];
		}
		var popmultiple=prop['multiple'];
		//click event
		var onclick = "";
		if (prop.dataprovider=="dataprovider-predefinedpopup") {//url page
			var popurl = '';
			if ('dataprovider-predefinedpopup'==prop.dataprovider) {
				popurl = prop['dataprovider-predefinedpopup'].realValue;
			}
			onclick = 'fmdf.onPopupinputBtnClickUrl(event, \''+popurl+'\','+popmultiple+')';
		} else if (prop.dataprovider=="dataprovider-modelselect") {//model select
			onclick = 'fmdf.onPopupinputBtnClickMs(event, '+
						'\''+ prop["dataprovider-modelselectmodel"] +'\','+
						popmultiple+')';
			var msl = prop["dataprovider-modelselectlist"];
			var attrOrder = ["ITEM_NO_"];
			var searchCols = [];
			var colHidden = {};
			var colWidth = {};
			var colAlign = {};
			var dpCols = {};
			var rvCol,dvCol;
			for (var i in msl) {
				attrOrder.push(msl[i].id);
				if (msl[i].search=="1") {
					searchCols.push(msl[i].id);
				}
				if (msl[i].hidden=="1") {
					colHidden[msl[i].id]=true;
				} else {
					//显示的列检查是否存在元数据配置
					if ("dataprovider-dict"==msl[i].meta) {
						Parser.generatedscript += 'fmdv.dataprovider["'+msl[i].metasource.type.toUpperCase()+'"]={"rtn":"enu","dp":"dict","type":"'+msl[i].metasource.type.toUpperCase()+'","target":"BPM"};\n';
						dpCols[msl[i].id] = "datactx.m.enu['"+msl[i].metasource.type.toUpperCase()+"']";
					} else if ("dataprovider-restsrv"==msl[i].meta) {
						Parser.generatedscript += 'fmdv.dataprovider["'+msl[i].metasource.realValue+'"]={"rtn":"enu","dp":"svc","svcid":"'+msl[i].metasource.realValue+'","intfvars":'+(msl[i].metasource.intfvars?JSON.stringify(msl[i].metasource.intfvars):"null")+'};\n';
						dpCols[msl[i].id] = "datactx.m.enu['"+msl[i].metasource.realValue+"']";
					}
				}
				if (msl[i].rv=='1') {
					rvCol = msl[i].id;
				}
				if (msl[i].dv=='1') {
					dvCol = msl[i].id;
				}
				colWidth[msl[i].id] = msl[i].width;
				colAlign[msl[i].id] = msl[i].align;
			}
			Parser.generatedscript += '\nfmdv.ui["'+conf.id+'"]={};\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"]={"rvCol":"'+rvCol+'","dvCol":"'+dvCol+'","attrOrder":'+JSON.stringify(attrOrder)+'};\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].searchCols='+JSON.stringify(searchCols)+';\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].dpCols='+JSON.stringify(dpCols)+';\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].colHidden='+JSON.stringify(colHidden)+';\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].colWidth='+JSON.stringify(colWidth)+';\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].colAlign='+JSON.stringify(colAlign)+';\n';
		} else if (prop.dataprovider=="dataprovider-restsrv") {//rest service
			var svcId = prop["dataprovider-restsrv"].realValue;
			onclick = 'fmdf.onPopupinputBtnClickSvc(event, \''+svcId+'\','+popmultiple+')';
		}
		
		transform.html = '<div class="col-md-'+cols[0]+'">'+
			    '<p'+
			    (prop["i18ntip-"+Parser.lang] ? (' title="'+prop["i18ntip-"+Parser.lang]+'"') : '') +
			    (prop.hideLabel=='1' ? ' style="display:none;"' : '')+
			    //(prop.inputreadonly=='1' ? ' readonly="readonly"' : '') +
			    '>'+prop["i18nname-"+Parser.lang]+
			    (required ? '<span class="xh">*</span>' : '') +
			    (prop["i18ntip-"+Parser.lang] ? ('&nbsp;<i class="glyphicon glyphicon-question-sign"></i>') : '')+
			    '</p>'+
			    '</div>'+
			    '<div class="col-md-'+cols[1]+'">'+
				    '<div class="input-group" style="position:relative;">'+
			            '<input type="text" class="form-control '+(prop.classNames ? prop.classNames : '')+'" id="'+conf.id+'" name="'+conf.id+
						'" type="text" value=""'+
						//(prop.disabled=='1' || prop.inputreadonly=='1' ? ' readonly="readonly"' : '') +
						//(prop["processbinding-displayvalue"] ? (' binding="'+prop["processbinding-displayvalue"]+'"') : '')+
						' readonly="readonly" desc="'+prop["i18nname-"+Parser.lang]+'"'+
						' databinding="'+prop["databinding-displayvalue"]+'" maxlength="'+ prop.maxlength + '"' +
						' ng-model="b.'+prop["databinding-displayvalue"]+'"' +
						' onchange="fmdf.onPopupinputChange(event)"' +
						' style="'+(prop["style"] || '')+'"'+
			            '/>'+
						'<input id="'+(conf.id+'-h')+'" name="'+(conf.id+'-h')+
						'" type="text" style="display:none;" value=""'+
						//(prop["processbinding-realvalue"] ? (' binding="'+prop["processbinding-realvalue"]+'"') : '')+
						' desc="'+prop["i18nname-"+Parser.lang]+'"'+
						' databinding="'+prop["databinding-realvalue"]+'"' + 
						' ng-model="b.'+prop["databinding-realvalue"]+'"' +
						'/>'+
			            '<span class="input-group-addon" style="cursor:pointer" '+
			            (prop.disabled=='1' || prop.inputreadonly=='1' ? '' : 'onclick="fmdf.onPopupinputBtnClear(event)"') +'>'+
			     			'<i class="glyphicon glyphicon-remove"></i>'+
			            '</span>'+
			            '<span class="input-group-addon" style="cursor:pointer" '+
			            (prop.disabled=='1' || prop.inputreadonly=='1' ? '' : 'onclick="'+onclick+'"')+'>'+
			     			'<i class="glyphicon glyphicon-search"></i>'+
			            '</span>'+
		            '</div>'+
			    '</div>';
		var wrapper = json2html.transform(data, transform);
		s += wrapper.substr(0, wrapper.length-4).substr(3);
	}
	return s;
};

Parser["control:popupinput:default:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		Parser.log(JSON.stringify(conf));
		Parser.log(JSON.stringify(prop));
		//Parser.parseDataProvider(conf.id);
		var required = Parser.parseValidator(conf.id);
		Parser.parseI18ntip(conf.id);
		var data = {};
		data.style = Parser.cssDisplay(prop.display)+(prop.style?prop.style:"")+(prop.margintop?"margin-top:"+prop.margintop:"");
		var transform = {"tag":"i"};
		var fmdcols = parseInt(conf.fmdcols);
		var cols = [1,fmdcols-1];
		if(fmdcols>3) {
			cols = [2,fmdcols-2];
		}
		
		var popmultiple=prop['multiple'];
		//click event
		var onclick = "";
		if (prop.dataprovider=="dataprovider-predefinedpopup") {//url page
			var popurl = '';
			if ('dataprovider-predefinedpopup'==prop.dataprovider) {
				popurl = prop['dataprovider-predefinedpopup'].realValue;
			}
			onclick = 'fmdf.onPopupinputBtnClickUrl(event, \''+popurl+'\','+popmultiple+')';
		} else if (prop.dataprovider=="dataprovider-modelselect") {//model select
			onclick = 'fmdf.onPopupinputBtnClickMs(event, '+
						'\''+ prop["dataprovider-modelselectmodel"] +'\','+
						popmultiple+')';
			var msl = prop["dataprovider-modelselectlist"];
			var attrOrder = ["ITEM_NO_"];
			var searchCols = [];
			var colHidden = {};
			var colWidth = {};
			var colAlign = {};
			var dpCols = {};
			var rvCol,dvCol;
			for (var i in msl) {
				attrOrder.push(msl[i].id);
				if (msl[i].search=="1") {
					searchCols.push(msl[i].id);
				}
				if (msl[i].hidden=="1") {
					colHidden[msl[i].id]=true;
				} else {
					//显示的列检查是否存在元数据配置
					if ("dataprovider-dict"==msl[i].meta) {
						Parser.generatedscript += 'fmdv.dataprovider["'+msl[i].metasource.type.toUpperCase()+'"]={"rtn":"enu","dp":"dict","type":"'+msl[i].metasource.type.toUpperCase()+'","target":"BPM"};\n';
						dpCols[msl[i].id] = "datactx.m.enu['"+msl[i].metasource.type.toUpperCase()+"']";
					} else if ("dataprovider-restsrv"==msl[i].meta) {
						Parser.generatedscript += 'fmdv.dataprovider["'+msl[i].metasource.realValue+'"]={"rtn":"enu","dp":"svc","svcid":"'+msl[i].metasource.realValue+'","intfvars":'+(msl[i].metasource.intfvars?JSON.stringify(msl[i].metasource.intfvars):"null")+'};\n';
						dpCols[msl[i].id] = "datactx.m.enu['"+msl[i].metasource.realValue+"']";
					}
				}
				if (msl[i].rv=='1') {
					rvCol = msl[i].id;
				}
				if (msl[i].dv=='1') {
					dvCol = msl[i].id;
				}
				colWidth[msl[i].id] = msl[i].width;
				colAlign[msl[i].id] = msl[i].align;
			}
			Parser.generatedscript += '\nfmdv.ui["'+conf.id+'"]={};\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"]={"rvCol":"'+rvCol+'","dvCol":"'+dvCol+'","attrOrder":'+JSON.stringify(attrOrder)+'};\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].searchCols='+JSON.stringify(searchCols)+';\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].dpCols='+JSON.stringify(dpCols)+';\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].colHidden='+JSON.stringify(colHidden)+';\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].colWidth='+JSON.stringify(colWidth)+';\n'+
					'fmdv.ui["'+conf.id+'"]["'+prop["dataprovider-modelselectmodel"]+'"].colAlign='+JSON.stringify(colAlign)+';\n';
		} else if (prop.dataprovider=="dataprovider-restsrv") {//rest service
			var svcId = prop["dataprovider-restsrv"].realValue;
			onclick = 'fmdf.onPopupinputBtnClickSvc(event, \''+svcId+'\','+popmultiple+')';
		}
		
		transform.html = '<div class="label col-md-'+cols[0]+'"'
			+ (data.style ? ' style="'+data.style+'"' : '')
			+'><p'
			+(prop["i18ntip-"+Parser.lang] ? (' title="'+prop["i18ntip-"+Parser.lang]+'"') : '')
			+(prop.hideLabel=='1' ? ' style="display:none;"' : '')
			+ '>'
			+(required ? '<span class="xh">*</span>' : '')
			+ prop["i18nname-"+Parser.lang]
			+ (prop["i18ntip-"+Parser.lang] ? ('&nbsp;<i class="glyphicon glyphicon-question-sign"></i>') : '')
			+ '</p>'
			+ '</div>'
			+ '<div class="item cellborder input-s col-md-'+cols[1]+'"'
			+ (data.style ? ' style="'+data.style+'"' : '')
			+ '><div class="input-group" style="position:relative;">'
			+ '<input class="form-control  ng-pristine ng-valid '+(prop.classNames ? prop.classNames : '')+'" id="'+conf.id+'" name="'+conf.id+'" type="text" value=""'
			+ (prop.disabled=='1' ? ' readonly="readonly"' : '') +
				//(prop["processbinding-displayvalue"] ? (' binding="'+prop["processbinding-displayvalue"]+'"') : '')+
				' readonly="readonly" desc="'+prop["i18nname-"+Parser.lang]+'"'+
				' databinding="'+prop["databinding-displayvalue"]+'" maxlength="'+ prop.maxlength + '"' +
				' ng-model="b.'+prop["databinding-displayvalue"]+'"' +
				' onchange="fmdf.onPopupinputChange(event)"' +
				' style="'+(prop["style"] || '')+'"'+
				'/>'+
				'<span class="cancel"'+
			            (prop.disabled=='1' || prop.inputreadonly=='1' ? '' : 'onclick="fmdf.onPopupinputBtnClear(event)"') +'>'+
			            '<i class="glyphicon glyphicon-remove"></i></span>'+
			            //hidden for realvalue
						'<input id="'+(conf.id+'-h')+'" name="'+(conf.id+'-h')+
						'" type="text" style="display:none;" value=""'+
						//(prop["processbinding-realvalue"] ? (' binding="'+prop["processbinding-realvalue"]+'"') : '')+
						' desc="'+prop["i18nname-"+Parser.lang]+'"'+
						' databinding="'+prop["databinding-realvalue"]+'"' + 
						' ng-model="b.'+prop["databinding-realvalue"]+'"' +
						'/>'+
				'<span class="input-group-btn" data-toggle="modal" data-target="#dialog-pop" '+
				//hidden for realvalue
					(prop.disabled=='1' || prop.inputreadonly=='1' ? '' : 'onclick="'+onclick+'"')+'>'+
			        '<button type="button" class="btn btn-default">'+
			     	'<i class="glyphicon glyphicon-search"></i>'+
			        '</button>'+
			'</span>'+
		'</div>'+
	'</div>';
		var wrapper = json2html.transform(data, transform);
		s += wrapper.substr(0, wrapper.length-4).substr(3);
	}
	return s;
};

